package com.web.controller;


import com.web.dao.学生情况Dao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

//定义当前请求处理的访问uri
@WebServlet("/deleteStudent")
public class StudentDeleteController extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("UTF-8");

        resp.setCharacterEncoding("GBK");

        String 学号 = req.getParameter("id");

        学生情况Dao dao = new 学生情况Dao();
        boolean isok = false;
        try {
            isok = dao.deleteStu(学号);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        if (isok) {
            req.getRequestDispatcher("/getAllStudent").forward(req, resp);
        } else {

            resp.getWriter().append("删除失败，请重新操作！");
        }
    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}